<?php
/**
 * @author Terence Yan <terence.yan@me.com>
 * Check Authetnication of submitted user and hash.
 * @param $username accountname
 * @param $pass password (hashed)
 * @return bool true false success status.
 */

include_once 'UTDBGlobal.php';
function checkAuthentication($username, $pass)
{
    global $dbaddress;
	global $dbuser;
    global $dbpassword;
    global $dbdatabasename;
	
    $output = false;

    $context = mysqli_connect($dbaddress, $dbuser, $dbpassword, $dbdatabasename);

    if (!mysqli_connect_errno()) {
        $query = "CALL GetAuthValue('$username')";

        if ($result = mysqli_query($context, $query)) {

            if ($obj = mysqli_fetch_object($result)) {

                if ($obj->password == $pass) {
                    $output = true;
                }

            }
            $result->close();
        }
        $context->close();
    } 

    return $output;
}

?>
